//
//  CJExten+UIGesture.swift
//  CJCore
//
//  Created by 陈警卫 on 2024-06-18.
//

import UIKit
import Foundation

public extension UIGestureRecognizer {
    
    private struct CJTapGestureKey {
        static var cj_tapClosure: Void?
    }
    
    @objc func cj_addAction(closure: @escaping (UIGestureRecognizer) -> ()) {
        objc_setAssociatedObject(self, &CJTapGestureKey.cj_tapClosure, closure, .OBJC_ASSOCIATION_COPY_NONATOMIC)
        addTarget(self, action: #selector(cj_tapClosureAction))
        
    }
    
    @objc func cj_tapClosureAction() {
        if let closure = objc_getAssociatedObject(self, &CJTapGestureKey.cj_tapClosure) as? ((UIGestureRecognizer) -> ()) {
            closure(self)
        }
    }
}
